//
//  CategoryView.m
//  ShanMei
//
//  Created by huazi on 15/3/18.
//  Copyright (c) 2015年 huazi. All rights reserved.
//

#import "CategoryView.h"
#define ktagCategoryFunctionView  1231
@implementation CategoryView

- (void)setSubviews
{
    for (int i=0; i<self.arrayItems.count; i++) {
        if ((i+8)/8==1) {
            NSDictionary *dic =[self.arrayItems objectAtIndex:i];
            CategoryFunctionView *_category =[[CategoryFunctionView alloc] initWithFrame:CGRectMake(kScaleDeviceLength(80*(i%4)),kScaleDeviceLength(80*(i/4)), kScaleDeviceLength(80),80)];
            _category.imageUrl =[dic objectForKey:@"picUrl"];
            _category.strLabelName =[dic objectForKey:@"name"];
            [_category setsubviews];
            [self addSubview:_category];
            _category.tag =ktagCategoryFunctionView +i;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
            tap.cancelsTouchesInView = NO;
            [_category addGestureRecognizer:tap];
            continue ;
        }
        if ((i+8)/8==2) {
            NSDictionary *dic =[self.arrayItems objectAtIndex:i];
            CategoryFunctionView *_category =[[CategoryFunctionView alloc] initWithFrame:CGRectMake(DeviceWidth+kScaleDeviceLength(80*(i%4)),kScaleDeviceLength(80*((i-8)/4)), kScaleDeviceLength(80),  kScaleDeviceLength(80))];
            _category.imageUrl =[dic objectForKey:@"picUrl"];
            _category.strLabelName =[dic objectForKey:@"name"];
            [_category setsubviews];
            [self addSubview:_category];
            _category.tag =ktagCategoryFunctionView +i;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
            tap.cancelsTouchesInView = NO;
            [_category addGestureRecognizer:tap];
             continue ;

        }
        NSDictionary *dic =[self.arrayItems objectAtIndex:i];
        CategoryFunctionView *_category =[[CategoryFunctionView alloc] initWithFrame:CGRectMake(DeviceWidth*2+kScaleDeviceLength(80*(i%4)),kScaleDeviceLength(80*((i-16)/4)), kScaleDeviceLength(80),  kScaleDeviceLength(80))];
        _category.imageUrl =[dic objectForKey:@"picUrl"];
        _category.strLabelName =[dic objectForKey:@"name"];
        [_category setsubviews];
        [self addSubview:_category];
        _category.tag =ktagCategoryFunctionView +i;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
        tap.cancelsTouchesInView = NO;
        [_category addGestureRecognizer:tap];
        
    }
    
//    UIImageView *imageDongTaiBJ =[[UIImageView alloc] initWithFrame:CGRectMake(0, 260, 320, 30)];
//    imageDongTaiBJ.image =[UIImage imageNamed:@"SHanMeiReMenBJ"];
//    [self addSubview:imageDongTaiBJ];
//    
//    UILabel *labelDongTai =[[UILabel alloc] initWithFrame:CGRectMake(10, 260, 100, 30)];
//    labelDongTai.text =@"热门动态";
//    labelDongTai.font =themeFont15;
//    labelDongTai.textColor =[UIColor whiteColor];
//    [self addSubview:labelDongTai];
}
- (void)singleTap:(UITapGestureRecognizer *)single{
    UIView *view =single.view;
    if (self.delegate &&[self.delegate respondsToSelector:@selector(CategoryViewSelect:andIndex:)]) {
        [self.delegate CategoryViewSelect:(CategoryFunctionView *)view andIndex:view.tag-ktagCategoryFunctionView];
    }
    
}
@end
